package douyin

import (
	"github.com/zeromicro/go-zero/core/logx"
	"io"
	"net/url"
	"xialou_platform/app/tools"
)

type QrCodeReq struct {
	Appname     string `json:"appname"`
	AccessToken string `json:"access_token"`
	Path        string `json:"path"`
	Width       int    `json:"width"`
	LineColor   struct {
		R int `json:"r"`
		G int `json:"g"`
		B int `json:"b"`
	} `json:"line_color"`
	Background struct {
		R int `json:"r"`
		G int `json:"g"`
		B int `json:"b"`
	} `json:"background"`
	SetIcon bool `json:"set_icon"`
}

func (c *DouYinClient) QrCode(req *QrCodeReq) ([]byte, error) {
	req.AccessToken = c.GetAccessToken()
	req.Path = url.QueryEscape(req.Path)
	resp, err := tools.Post(QRCodeUrl, req)
	if err != nil {
		logx.Errorf("err:%+v", err)
		return nil, err
	}
	data, err := io.ReadAll(resp.Body)
	if err != nil {
		logx.Errorf("err:%+v", err)
		return nil, err
	}
	return data, nil
}
